using System.Collections.Generic;
using UnityEngine;

namespace Minix{
    public class Projectile{
        static public bool Raycast(Vector3 origin, Vector3 init_velocity, Vector3 gravity, out Vector3 point,out List<Vector3> points,float projectile_step = 0.1f, float projectile_time = 3f, int layerMask = 0xffff){
            Vector3 pos = origin;//初始位置
            Vector3 velocity = init_velocity;//初速度
            List<Vector3> pts = new List<Vector3>();
            pts.Add(pos);
            for(float t = 0;t<projectile_time;t+=projectile_step){//每过一个时间周期
                var prePos = pos;
                pos += velocity * projectile_step;//移动一次位置
                velocity += gravity * projectile_step;//改变一次速度
                RaycastHit hitInfo;
                bool hit = Physics.Raycast(prePos, pos-prePos, out hitInfo, Vector3.Distance(prePos, pos), layerMask);
                if (hit){
                    pos = hitInfo.point;
                    point = pos;
                    pts.Add(pos);
                    points = pts;
                    return true;//hit block
                }
                pts.Add(pos);
            }
            point = Vector3.zero;
            points = pts;
            return false;
        }
    }
}